﻿namespace JumpJump.Runtime
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using JumpJump.Runtime;

    /// <summary>
    /// this class user for sotre one movement informations
    /// </summary>
    [Serializable]
    public class Movement
    {
        #region Fields

        /// <summary>
        /// Gets or sets the from position
        /// </summary>
        public Coordinate From
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the target position
        /// </summary>
        public Coordinate Target
        {
            get;
            set;
        }

        /// <summary>
        /// piece ID
        /// </summary>
        public int PieceID
        {
            get;
            set;
        }

        /// <summary>
        /// User ID
        /// </summary>
        public int UserID
        {
            get;
            set;
        }

        /// <summary>
        /// movement source
        /// </summary>
        public MovementSource Source
        {
            get;
            set;
        }

        /// <summary>
        /// this move score
        /// </summary>
        public int Score
        {
            get;
            set;
        }

        #endregion

        #region Constructor

        /// <summary>
        /// initialized a new instance
        /// </summary>
        /// <param name="userID">user ID</param>
        /// <param name="pieceId">piece ID</param>
        /// <param name="from">from coordinate</param>
        /// <param name="to">target coordinate</param>
        public Movement(int userID, int pieceId, Coordinate from, Coordinate to)
        {
            this.UserID = userID;
            this.PieceID = pieceId;
            this.From = from;
            this.Target = to;
            this.Source = MovementSource.None;
            this.Score = 0;
        }

        /// <summary>
        /// initialized a new instance
        /// </summary>
        /// <param name="userID">user ID</param>
        /// <param name="pieceId">piece ID</param>
        /// <param name="from">from coordinate</param>
        /// <param name="to">target coordinate</param>
        /// <param name="source">movement source</param>
        public Movement(int userID, int pieceId, Coordinate from, Coordinate to, MovementSource source)
        {
            this.UserID = userID;
            this.PieceID = pieceId;
            this.From = from;
            this.Target = to;
            this.Source = source;
            this.Score = 0;
        }

        /// <summary>
        /// initialized a new instance
        /// </summary>
        /// <param name="userID">user ID</param>
        /// <param name="pieceId">piece ID</param>
        /// <param name="from">from coordinate</param>
        /// <param name="to">target coordinate</param>
        /// <param name="source">movement source</param>
        /// <param name="score">movement score</param>
        public Movement(int userID, int pieceId, Coordinate from, Coordinate to, MovementSource source, int score)
        {
            this.UserID = userID;
            this.PieceID = pieceId;
            this.From = from;
            this.Target = to;
            this.Source = source;
            this.Score = score;
        }

        #endregion

        #region Propertites


        #endregion

        #region Public Methods

        public override bool Equals(object obj)
        {
            if(obj is Movement)
            {
                Movement send = obj as Movement;
                if (send.From.Equals(this.From) && send.Target.Equals(this.Target))
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
        }

        public override int GetHashCode()
        {
            int from = this.From.GetHashCode();
            int target = this.Target.GetHashCode();
            return from * 10000 + target;
        }

        public int GetMovementValue()
        {
            return 0;
        }

        #endregion

        #region Private Methods


        #endregion
    }

    /// <summary>
    /// describ the movement source
    /// </summary>
    public enum MovementSource
    { 
        ChessManual,
        Engine_LastStandAlonePiece,
        Engine_CommonMove,
        None,
    }
}
